﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EDiamondModel;


public partial class Pages_SanPhamCT : System.Web.UI.Page
{
    EDiamondEntities1 db = new EDiamondEntities1();
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!IsPostBack)
        {
            string idSP = Request.QueryString["idSP"];
            if (!String.IsNullOrEmpty(idSP))
            {
                int id = Convert.ToInt32(idSP);
                SanPham sp = db.SanPhams.FirstOrDefault(p => p.SanPhamID == id);
                hinh.ImageUrl = "~/Photos/SanPham/" + sp.Hinh;
                tenSanPham.Text = sp.TenSanPham;
                lblMoTa.Text = sp.MoTa;
                //lblDonGia.Text = "<b>Đơn giá: </b>" + sp.DonGia + "USD";
                if (sp.KhuyenMai.HasValue)
                    dongia.InnerHtml = (sp.DonGia.HasValue) ? "Giá: <span style='color: #f23f7a; font-size:12px; font-weight:Bold;text-decoration:line-through'>" + sp.DonGia.ToString() + " USD" + "</span>" : "";
                else
                    dongia.InnerHtml = (sp.DonGia.HasValue) ? "<span style='color: #f23f7a; font-size:12px; font-weight:Bold;'>" + sp.DonGia.ToString() + " USD" + "</span>" : "";
                if (sp.KhuyenMai.HasValue)
                    khuyenmai.InnerHtml = "Giá khuyến mãi: <span  style='color: #f23f7a;font-size:12px;font-weight:Bold;'>" + sp.KhuyenMai.ToString() +" USD" + "</span>";
                else
                    khuyenmai.Visible = false;

                double sl = GioHang.TongSanpham();
                double tg = GioHang.TongTrigia();
                Label SLuong = this.Page.Master.FindControl("SLuong") as Label;
                SLuong.Text = "<b>" + sl.ToString() + "<b>";
                Label TGia = this.Page.Master.FindControl("TGia") as Label;
                TGia.Text = "<b>" + tg.ToString() + "<b>";
            }
            comments.Attributes["data-href"] = HttpContext.Current.Request.Url.AbsoluteUri;
        }
    }
    protected void imgbtnChonMua_Click(object sender, ImageClickEventArgs e)
    {
        string idSP = Request.QueryString["idSP"];
        int ma = Convert.ToInt32(idSP);
        GioHang.MuaSp(ma, 1);
        //Response.Redirect("~/Pages/GioHang.aspx");
        double sl = GioHang.TongSanpham();
        double tg = GioHang.TongTrigia();
        Label SLuong = this.Page.Master.FindControl("SLuong") as Label;
        SLuong.Text = "<b>" + sl.ToString() + "<b>";
        Label TGia = this.Page.Master.FindControl("TGia") as Label;
        TGia.Text = "<b>" + tg.ToString() + "<b>";
    }
}